//
//  KZTimeCountDownView.m
//  听说弱点强化训练
//
//  Created by 朱凯 on 2018/10/22.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "KZRingTimerView.h"


@implementation KZRingTimerView
{
    UIView *_bgView;
    CAShapeLayer *_ringLayer;      // 环形倒计时
}

- (instancetype)init {
    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    CGFloat lineWidth = W(4);
    
    _bgView = UIView.new;
    [self addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(lineWidth + 2);
        make.right.bottom.mas_equalTo(-lineWidth - 2);
    }];
    
    _ringLayer = [CAShapeLayer layer];
    _ringLayer.lineWidth = lineWidth;
    _ringLayer.lineCap = kCALineCapRound;
    _ringLayer.fillColor = UIColor.clearColor.CGColor;
    [self.layer addSublayer:_ringLayer];
}
- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.layer.cornerRadius = self.width / 2;
    _bgView.layer.cornerRadius = self.width / 2 - _ringLayer.lineWidth - 2;
    
    // 环形路径
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.width / 2, self.height / 2) radius:(self.width - _ringLayer.lineWidth) / 2 startAngle:-M_PI/2 endAngle:M_PI/2*3 clockwise:true];
    _ringLayer.path = path.CGPath;
    _ringLayer.strokeEnd = 0;
    
    // 阴影
    self.layer.shadowOffset = CGSizeMake(0, 0);
    self.layer.shadowRadius = 15;
    self.layer.shadowOpacity = 0.6;
}




@end
